import Vue from 'vue'
import Router from 'vue-router'
import Home from "@/Views/Home/Home";
import Virtual from "@/Views/Virtual/Virtual";
import Observe from "@/Views/Observe/Observe";
Vue.use(Router)

// 解决vue路由重复点击报错问题
const originalPush = Router.prototype.push;
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = new Router({
  mode: 'hash',
  routes: [
    {
      path: '/',
      component: () => import('@/Views/Layout/Layout.vue'),
      children: [
        {path: '/', redirect: '/home'},
        {path: 'home', component: Home},
        {path: 'virtual', component: Virtual},
        {path: 'observe', component: Observe},
      ]
    }
  ]
})

/*routes.beforeEach((to, from, next) => {
  const arr = ['/login','/error']
  if (arr.includes(to.path)) {
    next(true)
  } else if (Vue.localStorage.get('userCode')){
    const arr2 = ['/home','/test','/store','/assets']
    if (arr2.includes(to.path)) {
      next(true)
    } else {
      let success = []
      JSON.parse(Vue.localStorage.get('routers')).map((val) => {
        success.push(val.permissionName)
      })
      if (success.includes(to.path)) {
        next(true)
      } else {
        next({path: '/error'})
      }
    }
  } else {
    next({path: '/error'})
  }
})*/
export default routes
